package jsp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Miss Chen
 * @version 1.0
 * @date 2024年09月03日10:17
 */

// @WebServlet("/show")
@WebServlet("/show/*")
public class ShowServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 无法直接访问WEB-INF下面的页面的http://localhost:8080/web/WEB-INF/b/test03.jsp
        // 可以转发的方式来访问

        String uri=request.getRequestURI();
        System.out.println(uri);
        String contextPath=request.getContextPath();
        System.out.println(contextPath);
        String servletPath=request.getServletPath();
        System.out.println(servletPath);
        String path=uri.substring((contextPath+servletPath).length());//截取
        System.out.println(path);

        request.getRequestDispatcher("/WEB-INF/"+path+".jsp").forward(request,response);
    }
}
